package com.woniu.commentorder.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;

@Configuration
public class RabbitmqConfig {
    @Bean
    public TopicExchange OrderExchange() {
        return new TopicExchange("orderexchange");
    }
    @Bean
    public TopicExchange videoExchange() {
        return new TopicExchange("videoexchange");
    }
    @Bean
    public TopicExchange deadExchange() {
        return new TopicExchange("deadexchange");
    }
    @Bean
    public Queue payRecordQueue() {
        HashMap<String, Object> args = new HashMap<>();
        args.put("x-message-ttl", 10000);
        args.put("x-dead-letter-exchange", "deadexchange");
        args.put("x-dead-letter-routing-key", "dead");
        return new Queue("payrecordqueue",true,false,false,args);
    }
    @Bean
    public Queue deadQueue() {
        return new Queue("deadqueue");
    }
    @Bean
    public Queue walletQueue() {
        return new Queue("walletqueue");
    }

    @Bean
    public Queue goodsQueue() {
        return new Queue("goodsqueue");
    }

    @Bean
    public Binding orderBinding() {
        return BindingBuilder.bind(payRecordQueue()).to(OrderExchange()).with("#.payRecord.#");
    }

    @Bean
    public Binding goodsBinding() {
        return BindingBuilder.bind(goodsQueue()).to(OrderExchange()).with("#.goods.#");
    }

    @Bean
    public Binding walletBinding() {
        return BindingBuilder.bind(walletQueue()).to(OrderExchange()).with("#.wallet.#");
    }
    @Bean
    public Binding deadBinding() {
        return BindingBuilder.bind(deadQueue()).to(deadExchange()).with("#.dead.#");
    }
}
